<?php

class Front_Form_Register extends Zend_Form
{
    public function init() {
        parent::init();
        
        $this->setMethod('post');
        
        $this->setAction('/front/register');

        $usernameUnique = new Front_Validator_NoRecordExists(
            array('entityManager' => Zend_Registry::get('entitymanager'),
                'class' => 'Entities\User',
                'property' => 'username',
                )
            );
        $username = new Zend_Form_Element_Text('username');  
        $username->setLabel('Username:')  
                ->setAttrib('placeholder', 'Username')
                ->setRequired(true)
                ->addValidator('StringLength', false, array(6, 32))
                ->addValidator($usernameUnique)
                ;
//        $username->removeDecorator('Errors');
      
        $password = new Zend_Form_Element_Password('password');  
        $password->setLabel('Password:') 
                ->setAttrib('placeholder', 'password')
                ->setRequired(true)
                ->addValidator('StringLength', false, array(6, 50));
//        $password->removeDecorator('Errors');
      
        $confirm = new Zend_Form_Element_Password('confirm');  
        $confirm->setLabel('Confirm Password:') 
                ->setAttrib('placeholder', 'confirm password')
                ->setRequired(true)
                ->addValidator('Identical', false, array('token' => 'password'))
                ->addErrorMessage('The passwords do not match');
//        $confirm->removeDecorator('Errors');

        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Name:')
                ->setAttrib('placeholder', 'name')
                ->setRequired(true)
                ->addValidator('StringLength', false, array(6, 255));
//        $name->removeDecorator('Errors');
      
        $mobile = new Zend_Form_Element_Text('mobile');
        $mobile->setLabel('MobilePhone:')
                ->setAttrib('placeholder', 'mobile')
                ->setRequired(false);
//        $mobile->removeDecorator('Errors');

        $emailUnique = new Front_Validator_NoRecordExists(
            array('entityManager' => Zend_Registry::get('entitymanager'),
                'class' => 'Entities\User',
                'property' => 'email',
                )
            );
        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Email:')
                ->setAttrib('placeholder', 'email')
                ->setRequired(true)
                ->addValidator('EmailAddress')
                ->addValidator($emailUnique)
                ;
//        $email->removeDecorator('Errors');

        $department = new Zend_Form_Element_Select('department');
        $department->setLabel('Department:')
                ->setRequired(false)
                ;
        $_em = Zend_Registry::get('entitymanager');
        $depts = $_em->getRepository('Entities\Department')->findAllList();
//        var_dump($depts); die;
        $department->addMultiOptions($depts);
//        $department->removeDecorator('Errors');
        
        $submit = new Zend_Form_Element_Submit('Register');  
        $submit->setLabel('Register');  
      
        $reset = new Zend_Form_Element_Reset('Reset');  
        $reset->setLabel('Reset');  
      
        $this->addElement($username)  
                ->addElement($password)  
                ->addElement($confirm)
                ->addElement($name)
                ->addElement($mobile)
                ->addElement($email)
                ->addElement($department)
                ->addElement($submit)
                ->addElement($reset);
        
        $this->setDecorators(array(
            'FormErrors',
            'FormElements',
            'Form',
        ));
    }
}

//            new Zend_Form_Decorator_Errors(array(
//                'ignoreSubforms' => true,
//                'markupElementLabelStart' => '<b>',
//                'markupElementLabelEnd' => '</b>',
//                'markupListStart' => '<div>',
//                'markupListEnd' => '</div>',
//                'markupListItemStart' => '<span>',
//                'markupListItemEnd' => '</span>'
//            )),